package com.leonzx.base.config.datasource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Created by liang on 2018/3/28.
 */
public class DataSourceContextHolder {

    private static final Logger logger = LoggerFactory.getLogger(DataSourceContextHolder.class);

    /**
     * 默认数据源
     */
    public static final String DEFAULT_DS = "leonlims";

    private static final ThreadLocal<String> contextHolder = new ThreadLocal<>();

    /**
     * 设置数据源名
     *
     * @param dbType 数据源名称
     */
    public static void setDB(String dbType) {
        logger.info("切换到{}数据源", dbType);
        contextHolder.set(dbType);
    }

    /**
     * 获取数据源名称
     *
     * @return
     */
    public static String getDB() {
        return (contextHolder.get());
    }

    /**
     * 清搐数据源名称
     *
     */
    public static void clearDB() {
        contextHolder.remove();
    }
}
